package com.itheima.reggie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.reggie.entity.DishFlavor;
import com.itheima.reggie.mapper.DishFlavorMapper;
import com.itheima.reggie.service.DishFlavorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class DishFlavorServiceImpl implements DishFlavorService {
    
    @Autowired
    private DishFlavorMapper mapper ;
    
    /**
     * 根据菜品的id，查询这个菜品的口味数据
     *
     * @param dishId
     * @return
     */
    @Override
    public List<DishFlavor> findByDishId(long dishId) {
        
        //1. 设置查询条件
        LambdaQueryWrapper<DishFlavor> qw = new LambdaQueryWrapper<>();
        qw.eq(DishFlavor::getDishId , dishId);
        
        return mapper.selectList(qw);
    }
    
    /**
     * 添加口味数据
     *
     * @param dishFlavor
     * @return
     */
    @Override
    public int add(DishFlavor dishFlavor) {
        return mapper.insert(dishFlavor);
    }
    
    /**
     * 根据菜品的id，删除掉这个菜品的所有口味数据
     *
     * @param dishId
     * @return
     */
    @Override
    public int delete(long dishId) {
        
        //1. 定义条件
        LambdaQueryWrapper<DishFlavor> qw = new LambdaQueryWrapper<>();
        qw.eq(DishFlavor::getDishId , dishId);
        
        //2. 执行删除
        return mapper.delete(qw);
    }
}
